<template>
  <!-- 毕业管理 -->
  <div class="app-container">
    <!-- 搜索 -->
    <el-card class="search-card">
      <el-form
        :model="queryParams"
        ref="queryParams"
        size="small"
        class="formBox"
        label-width="88px"
      >
        <el-row :gutter="0">
          <el-col :span="5">
            <el-form-item label="姓名" prop="name">
              <el-input
                v-model="queryParams.name"
                placeholder="请输入姓名"
                clearable
                maxlength="50"
                show-word-limit
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="身份证号" prop="idCardNumber">
              <el-input
                v-model="queryParams.idCardNumber"
                placeholder="请输入身份证号"
                clearable
                maxlength="18"
                show-word-limit
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="年级" prop="gradeId">
              <el-select
                v-model="queryParams.gradeId"
                placeholder="请选择年级名称"
                @keyup.enter.native="handleQuery"
                style="width: 100%"
                @change="gradeFun_1"
              >
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :value="item.id"
                  :label="item.gradeName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="班级" prop="classId">
              <el-select
                v-model="queryParams.classId"
                placeholder="请选择班级"
                @keyup.enter.native="handleQuery"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in classList_1"
                  :key="index"
                  :value="item.id"
                  :label="item.className"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="退款状态" prop="refundStatus">
              <el-select
                v-model="queryParams.refundStatus"
                placeholder="请选择退款状态"
                @keyup.enter.native="handleQuery"
                style="width: 100%"
              >
                <el-option value="0" label="未退款"> </el-option>
                <el-option value="1" label="退款中"> </el-option>
                <el-option value="2" label="退款成功"> </el-option>
                <el-option value="3" label="退款失败"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item>
              <div class="dis aic">
                <div class="flex_1"></div>
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="handleQuery"
                >
                  搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
                  重置
                </el-button>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <!-- 按钮 -->
    <el-card class="search-card">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            size="mini"
            v-hasPermi="['student:graduate:batchRefund']"
            @click="BatchRefundFun"
            >批量退款
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            v-hasPermi="['student:graduate:export']"
            @click="handleExport"
            >导出
          </el-button>
        </el-col>
        <right-toolbar @queryTable="getList"></right-toolbar>
      </el-row>
    </el-card>
    <!-- 列表 -->
    <el-card class="table-card">
      <el-table v-loading="loading" :data="personList" stripe border>
        <el-table-column label="姓名" align="center" prop="name" width="100" />
        <el-table-column label="手机号" align="center" prop="phoneNumber" width="120" />
        <el-table-column
          label="身份证号"
          align="center"
          prop="idCardNumber"
          width="180"
        />
        <el-table-column label="学校" align="center" prop="schoolName" width="100" />
        <el-table-column label="年级" align="center" prop="gradeName" width="120" />
        <!-- <el-table-column label="班级" align="center" prop="className" width="120" /> -->
        <el-table-column label="身份" align="center" prop="identityId">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.personnel_identity"
              :value="scope.row.identityId"
            />
          </template>
        </el-table-column>
        <el-table-column label="钱包余额" align="center" prop="walletBalance" width="130">
          <template slot-scope="scope">
            {{ scope.row.walletBalance ? scope.row.walletBalance : 0 }}元
          </template>
        </el-table-column>
        <el-table-column label="退款状态" align="center" prop="refundStatus">
          <template slot-scope="scope">
            <span v-if="scope.row.refundStatus == 0">未退款</span>
            <span v-if="scope.row.refundStatus == 1">退款中</span>
            <span v-if="scope.row.refundStatus == 2">退款成功</span>
            <span v-if="scope.row.refundStatus == 3">退款失败</span>
          </template>
        </el-table-column>
        <el-table-column
          label="失败原因"
          align="center"
          prop="remarks"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="260"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              class="padding_4_10"
              @click="RefundFun(scope.row)"
              v-if="scope.row.refundStatus != 2"
              v-hasPermi="['student:graduate:refund']"
            >
              退款
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>
<script>
import { graduateList, graduateRefund, graduateBatchRefund } from "@/api/campus/graduate";
import { listGrade } from "@/api/campus/grade";
import { listClassManage } from "@/api/campus/classManage";

export default {
  name: "studentGraduate",
  dicts: ["facial_state", "sys_open_status", "personnel_identity"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 人员管理表格数据
      personList: [],
      // 弹出层标题
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        idCardNumber: null,
        schoolName: null,
        gradeName: null,
        className: null,
        identityName: null,
        identityId: null,
        walletBalance: null,
        dailySpendingLimit: null,
        monthlySpendingLimit: null,
        phoneNumber: null,
        isEnabled: null,
      },
      // 表单参数
      form: {
        gradeId: "",
        classId: "",
        name: "",
        idCardNumber: "",
        identityId: "",
        refundStatus: "",
      },
      // 表单校验
      rules: {
        name: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
        idCardNumber: [{ required: true, message: "身份证号不能为空", trigger: "blur" }],
      },
      gradeList: [],
      classList_1: [],
      classList_2: [],
      goSchoolSetForm: {},
      status: false,
    };
  },
  created() {
    this.getList();
    this.listGradeFun();
    this.gradeFun_1();
    this.gradeFun_2();
  },
  activated() {
    this.getList();
    this.listGradeFun();
    this.gradeFun_1();
    this.gradeFun_2();
  },
  methods: {
    /** 查询人员管理列表 */
    getList() {
      this.loading = true;
      graduateList(this.queryParams).then((response) => {
        this.personList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    listGradeFun() {
      listGrade({ pageNum: 1, pageSize: 200 }).then((res) => {
        if (res.code == 200) {
          this.gradeList = res.rows;
        }
      });
    },
    gradeFun_1(options) {
      this.$set(this.queryParams, "classId", "");
      listClassManage({ pageNum: 1, pageSize: 200, gradeId: options }).then(
        (response) => {
          this.classList_1 = response.rows;
        }
      );
    },
    gradeFun_2(options) {
      listClassManage({ pageNum: 1, pageSize: 200, gradeId: options }).then(
        (response) => {
          this.classList_2 = response.rows;
        }
      );
    },

    // 取消按钮
    cancel() {
      this.status = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        gradeId: "",
        classId: "",
        name: "",
        idCardNumber: "",
        identityId: "",
        refundStatus: "",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryParams");
      this.handleQuery();
    },
    BatchRefundStatusFun() {
      this.status = true;
    },
    BatchRefundFun() {
      var that = this;
      this.$confirm("此操作将批量退款, 是否继续?", "批量退款", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          graduateBatchRefund(that.queryParams).then((res) => {
            if (res.code == 200) {
              that.$modal.msgSuccess(res.msg);
              that.getList();
            } else {
              that.$modal.msgError(res.msg);
            }
          });
        })
        .catch(() => {
          that.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    RefundFun(options) {
      var that = this;
      this.$confirm("是否操作退款？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then((res) => {
          console.log(res, "rrrrrrr");
          graduateRefund({ personId: options.id, refundReason: "离校退款" })
            .then((response) => {
              if (response.code == 200) {
                that.getList();
                that.$modal.msgSuccess(response.msg);
              } else {
                that.$modal.msgError(response.msg);
              }
            })
            .catch((error) => {
              console.error(error);
            });
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/campus/graduate/export",
        {
          ...this.queryParams,
        },
        "离线人员导出.xlsx"
      );
    },
  },
};
</script>
<style>
.padding_4_10 {
  padding: 4px 10px !important;
}
</style>
